import { GBox } from "../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../com/mui/containers/globalVariable/GBoxDirection";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Language } from "../../../../extend/language/Language";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { NationalTreasureInfo } from "../../model/NationalTreasureInfo";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { NationalTreaCheckItem } from "./NationalTreaCheckItem";
//class NationalTreasureCheckPanel
    
    export  class NationalTreasureCheckPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            mouseEnabled = false;
            return;
        }

        protected initUI(): void
        {
            this._bodySprite = new GBox();
            this._bodySprite.direction = GBoxDirection.VERTICAL;
            addChild(this._bodySprite);
            this._optBtn = new GButton();
            this._optBtn.setSize(70, 24);
            this._optBtn.styleName = "Button";
            this._optBtn.label = Language.getString(27022);
            this._optBtn.textField.filters = [FilterConst.nameGlowFilter];
            this._optBtn.x = 100;
            this._optBtn.y = 17;
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtnClickHandler);
            return;
        }

        /* internal  */onOptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NationalTreasureJoinReq));
            return;
        }

        public updateData(arg1: NationalTreasureInfo): void
        {
            var loc1=0;
            var loc3=null;
            var loc4=null;
            this.dispose();
            this._info = arg1;
            var loc2=arg1.checkInInfos.length;
            while (loc1 < loc2) 
            {
                loc3 = arg1.checkInInfos[loc1];
                (loc4 = ObjectPool.getObject(NationalTreaCheckItem)).updateData(loc3.camp, loc3.value, arg1.hasCheckIn && arg1.checkInStart, arg1.isCampOpen(loc3.camp));
                this._bodySprite.addChild(loc4);
                ++loc1;
            }
            this._bodySprite.invalidate();
            if (!arg1.hasCheckIn || !arg1.checkInStart) 
            {
                if (!contains(this._optBtn)) 
                {
                    addChild(this._optBtn);
                }
            }
            else if (contains(this._optBtn)) 
            {
                removeChild(this._optBtn);
            }
            return;
        }

        public dispose(): void
        {
            var loc1=null;
            while (this._bodySprite.numChildren > 0) 
            {
                loc1 = this._bodySprite.removeChildAt(0) as NationalTreaCheckItem;
                loc1.dispose();
                ObjectPool.disposeObject(loc1);
            }
            this._info = null;
            return;
        }

        protected /* var */_info: NationalTreasureInfo;

        protected /* var */_bodySprite: GBox;

        protected /* var */_optBtn: GButton;
    }
